var vm;
//var userCode=sessionStorage.getItem("cusId");
var test = sessionStorage.getItem("test");
var userCode = '0ace05c2';
$(function () {
	vm = new Vue({
        el: '#amountLog',
        data: {
            tabsShow:true,
            detail:false,
            add:false,
            clicktag:0,//防重复提交
            query:{
            	cusId		: userCode,
            	startDate	: '',
            	endDate		: '',
            	type		: ''
            }
        },
        methods: {
        	queryAmountLog:function(){
        		console.log("click button");
        		console.log("test:"+test);
        		vm.reload();
        	},
        	reload:function(){
//        		var start = this.$refs.startDate.value;
//        		var end = this.$refs.endDate.value;
//        		if(typeof(start) == 'undefined' || start == null || start == ''){
//        			$("#startDate").val(get7DaysAgo());
//        		}
//        		if(typeof(end) == 'undefined' || end == null || end == ''){
//        			$("#endDate").val(getNowTime());
//        		}
        		vm.query.startDate = this.$refs.startDate.value;
        		vm.query.endDate = this.$refs.endDate.value;
        		vm.query.type = this.$refs.trendType.value;
        		
        		console.log("vm.query.type:"+vm.query.type);
        		
        		
        		$("#jqGrid").setGridParam({
                    postData: {
                    	startTime	: vm.query.startDate,
                    	endTime		: vm.query.endDate,
                    	userCode	: vm.query.cusId,
                    	type		: vm.query.type
                    },
                    page:1
                }).trigger("reloadGrid");
        	}
        }
    });
	
	$("#jqGrid").jqGrid({
        url: '../amount_log/list_records',
        datatype: "json",
        postData: {
        	startTime	: vm.query.startDate,
        	endTime		: vm.query.endDate,
        	userCode	: vm.query.cusId,
        	type		: vm.query.type
        },
        colModel: [
            {label: 'id', name: 'id', key: true,hidden:true },
            {label: '交易时间', name: 'create_time'},
            {label: '交易类型', name: 'trend_type'},
            {label: '交易金额(元)', name: 'operation_amount'},
            {label: '可用金额(元)', name: 'available_amount_after' },
            {label: '状态', name: 'status' }
        ],
        viewrecords: true,
        height: 500,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 55,
        autowidth: true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",//总页数
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
        	console.log("asasasa");
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqGrid-bdiv").css({"overflow-x": "hidden"});
            //$("#jqGrid").jqGrid("setGridWidth",$(window).width());
        }
    });
	
	getDatas();
	
	function getDatas(){
//		$("#startDate").val(get7DaysAgo());
//		$("#endDate").val(getNowTime());
		vm.queryAmountLog();
	}
	
	function getNowTime(){
		var myDate = new Date();
		var year = myDate.getFullYear();
		var month = myDate.getMonth()+1;
		var date = myDate.getDate(); 
		var h = myDate.getHours(); 
		var m = myDate.getMinutes();
		var now = year + '-' + p(month) + "-" + p(date) + " " + p(h) + ':' + p(m) + ":00";
		return now;
	}
	
	function get7DaysAgo() {
	    var date = new Date();
	    date.setDate(date.getDate() - 7);
	    var year = date.getFullYear();
	    var month = date.getMonth() + 1;
	    var day = date.getDate(); 
		var h = date.getHours(); 
		var m = date.getMinutes();
	    var currentdate = year + "-" + p(month) + "-" + p(day) + " " + p(h) + ":" + p(m) + ":00" ;
	    return currentdate;
	}
	
	function p(s){
		return s < 10 ? '0' + s : s;
	}
});

